package com.daiyang.campus_lucky_draw.mapper;

import com.daiyang.campus_lucky_draw.mapper.DO.Encrypt;
import com.daiyang.campus_lucky_draw.mapper.DO.UserDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Insert("insert into user (user_name,email,phone_number,password,identity) " +
            "values (#{userName},#{email},#{phoneNumber},#{password},#{identity})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    Long insert(UserDO userDO);
    @Select("select  count(*) from user where phone_number = #{phoneNumber}")
    int countByPhoneNumber(Encrypt encrypt);
    @Select("select count(*) from user where email = #{email}")
    int countByMail(String  email);
    /**
     * 通过邮箱查询⽤⼾信息
     *
     * @param email
     * @return
     */
    @Select("select id, gmt_create, gmt_modified,"
            + " user_name, email, phone_number, password, identity"
            + " from user where email = #{email}")
    UserDO selectByEmail(@Param("email") String email);

    /**
     * 通过⼿机号查询⽤⼾信息
     *
     * @param phoneNumber
     * @return
     */
    @Select("select id, gmt_create, gmt_modified," +
            " user_name, email, phone_number, password, identity" +
            " from user where phone_number = #{phoneNumber}")
    UserDO selectByPhoneNumber(@Param("phoneNumber") Encrypt phoneNumber);
    @Select("<script>"
            + " SELECT * FROM user"
            + " <if test=\"identity != null\">"
            + " WHERE identity = #{identity}"
            + " </if>"
            + " order by id desc"
            + " </script>")
    List<UserDO> selectUserList(@Param("identity") String identityString);
    @Select("<script>" +
            " select id from user" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<Long> selectExistByIds(@Param("items") List<Long> ids);
    @Select("<script>"+
            " select * from user " +
            " where id in " +
            " <foreach  item='item'  collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            "</script>")
    List<UserDO> bathcSelectByIds(@Param("items") List<Long> items);
}
